﻿package com.tudou.home.newskin.containers
{
    import com.tudou.home.newskin.buttons.*;
    import com.tudou.home.newskin.events.*;
    import com.tudou.skin.common.behavior.*;
    import com.tudou.skin.common.consts.*;
    import com.tudou.skin.common.events.*;
    import com.tudou.track.*;
    import flash.display.*;

    public class Brightness extends Sprite implements IBrightness, ISelect, IAutoClose, IShowWidthHeight
    {
        private var $autoData:Object;
        private var bar:BrightnessBar;
        private var button:BrightnessButton;

        public function Brightness()
        {
            $autoData = {};
            bar = new BrightnessBar();
            button = new BrightnessButton();
            addChild(bar);
            addChild(button);
            bar.addEventListener(BarEvent.START_DRAG, barHlr);
            bar.addEventListener(BarEvent.DRAGING, barHlr);
            bar.addEventListener(BarEvent.END_DRAG, barHlr);
            button.addEventListener(SelectEvent.CLICK, selectHlr);
            selected = false;
            setBrightness(0);
            return;
        }// end function

        public function set autoData(param1:Object) : void
        {
            $autoData = param1;
            return;
        }// end function

        public function get enable() : Boolean
        {
            return button.enable;
        }// end function

        public function get showHeight() : uint
        {
            return button.height;
        }// end function

        public function set enable(param1:Boolean) : void
        {
            if (param1 == false && selected == true)
            {
                selected = false;
            }
            button.enable = param1;
            return;
        }// end function

        public function getBrightness() : Number
        {
            return bar.getValue();
        }// end function

        public function autoClose() : void
        {
            selected = false;
            return;
        }// end function

        private function selectHlr(event:SelectEvent) : void
        {
            selected = !event.selected;
            return;
        }// end function

        public function setBrightness(param1:Number) : void
        {
            bar.setValue(param1);
            return;
        }// end function

        public function get showWidth() : uint
        {
            return button.width;
        }// end function

        public function get selected() : Boolean
        {
            return button.selected;
        }// end function

        private function barHlr(event:BarEvent) : void
        {
            var _loc_2:String = null;
            if (event.type == BarEvent.END_DRAG)
            {
                _loc_2 = SkinEvent.END_SET_BRIGHTNESS;
            }
            else if (event.type == BarEvent.START_DRAG)
            {
                _loc_2 = SkinEvent.SET_BRIGHTNESS;
                dispatchEvent(new SkinEvent(SkinEvent.BUTTON_LOG, SkinButtonCode.BRIGHTNESS));
            }
            else
            {
                _loc_2 = SkinEvent.SET_BRIGHTNESS;
            }
            dispatchEvent(new SkinEvent(_loc_2, event.value));
            return;
        }// end function

        public function getCloseTime() : Number
        {
            return CommonConsts.AUTO_CLOSE_TIME;
        }// end function

        public function getSkin() : InteractiveObject
        {
            return this;
        }// end function

        public function get autoData() : Object
        {
            return $autoData;
        }// end function

        public function set selected(param1:Boolean) : void
        {
            if (param1)
            {
                AutoCloseUtil.actBehavior(this);
            }
            else
            {
                AutoCloseUtil.removeBehavior(this);
            }
            button.selected = param1;
            bar.visible = param1;
            return;
        }// end function

    }
}
